package com.title3;

import java.io.File;
import java.util.Scanner;

/**
 * @Author milian
 * @Date 2021/7/31 0031 20:34
 */
public class title3 {
    public static void main(String[] args) {
        System.out.println("请输入文件夹路径：");
        Scanner sc = new Scanner(System.in);
        String path = sc.nextLine();
        File file = new File(path);
        System.out.println("该文件夹大小为"+getFileLength(file));
    }

    private static long getFileLength(File file) {
        long fileSize = 0L;
        File[] files = file.listFiles();
        for (File file1 : files) {
            if (file1.isFile()){
                fileSize+=file1.length();
            }else {
                fileSize+=getFileLength(file1);
            }

        }
        return fileSize;
    }
}
